const { Stu } = require('../utils/db')

const queryList = async ({ pagenum, pagesize }) => {
	// 
	let result = {}
	// result.data = Stu.find().limit(pagesize).skip((pagenum - 1) * pagesize).sort({ id: 1 })
	// db.jay.find({name:'m1'}).count()   
	result = await Promise.all([
		Stu.count(),
		Stu.find().limit(pagesize).skip((pagenum - 1) * pagesize).sort({ id: 1 })
	]);
	return {
		totalNum: result[0],
		data: result[1]
	}
}

const addOne = ({ id, name, updateTime }) => {
	const spider = new Stu({
		id, name, updateTime
	})
	return spider.save()
}
exports.queryList = queryList
exports.addOne = addOne
